function plotCSloadings(CSdata,outEstim)

FontSizeValue   = 18;
figureSize      = [0 0 1000+300 600+300]; % (0,0) size in x size in y

version = 1;

CSmodel.maturities = CSdata.maturities;
CSmodel.CSbetta  = zeros(2,length(CSmodel.maturities));
if length(outEstim.outFilter.resMoments.CS_loadings) > length(CSmodel.maturities)
    CSmodel.CSbetta(2,:) = outEstim.outFilter.resMoments.CS_loadings(CSmodel.maturities);
else
    CSmodel.CSbetta(2,:) = outEstim.outFilter.resMoments.CS_loadings;
end

%% Figure 1
figure('Name','CS loadings','NumberTitle','off','Position',figureSize)
hold on
if version == 1
    xaxis       = CSdata.maturities(2:end)/4; 
    reverseaxis = CSdata.maturities(length(CSdata.maturities):-1:2)/4; 
    index       = 2:length(CSdata.CSbetta(2,:));
    reversIndex = length(CSdata.CSbetta(2,:)):-1:2;
    %grpyat = [xaxis'       CSdata.CSBetta_CI95Boot(1,index)';...
    %      reverseaxis' CSdata.CSBetta_CI95Boot(2,reversIndex)'];
    grpyat = [xaxis'       CSdata.CSBetta_prcBootCI95(1,index)';...
          reverseaxis' CSdata.CSBetta_prcBootCI95(2,reversIndex)'];
    patch(grpyat(:,1),grpyat(:,2),[0.8 0.8 0.8],'edgecolor',[0.6 0.6 0.6]);
else
    plot(CSdata.maturities(2:end)/4,CSdata.CSBetta_CI95Boot(1,2:end),'--k')
    plot(CSdata.maturities(2:end)/4,CSdata.CSBetta_CI95Boot(2,2:end),'--k')
end
plot(CSdata.maturities(2:end)/4,CSdata.CSbetta(2,2:end),'-k')
plot(CSdata.maturities(2:end)/4,CSdata.CSbetta(2,2:end)*0+1,':k')

set(gca,'FontSize',FontSizeValue)
axis([min(CSdata.maturities(2:end)/4) max(CSdata.maturities(2:end)/4)...
    min(CSdata.CSBetta_CI95Boot(:))*1.1 1.5] )
%ylabel('$\beta_k $','Interpreter','Latex','FontSize',FontSizeValue);
xlabel('Maturity in years','FontSize',FontSizeValue)
legend({'CI 95 pct','Data'},'Orientation','horizontal','FontSize',FontSizeValue+2,'EdgeColor',[0.15 0.15 0.15],...
    'Position',[0.384822896027229 0.939478465696058 0.243629479375424 0.0675996218505801],'FontSize',FontSizeValue);
legend boxoff  

%% Figure 2
figure('Name','CS loadings and the Model','NumberTitle','off','Position',figureSize)

yMax        = 3;
yMin        = -4;

hold on
if version == 1
    xaxis       = CSdata.maturities(2:end)/4; 
    reverseaxis = CSdata.maturities(length(CSdata.maturities):-1:2)/4; 
    index       = 2:length(CSdata.CSbetta(2,:));
    reversIndex = length(CSdata.CSbetta(2,:)):-1:2;
    %grpyat = [xaxis'       CSdata.CSBetta_CI95Boot(1,index)';...
    %      reverseaxis' CSdata.CSBetta_CI95Boot(2,reversIndex)'];
    grpyat = [xaxis'       CSdata.CSBetta_prcBootCI95(1,index)';...
          reverseaxis' CSdata.CSBetta_prcBootCI95(2,reversIndex)'];
    patch(grpyat(:,1),grpyat(:,2),[0.8 0.8 0.8],'edgecolor',[0.6 0.6 0.6]);
else
    plot(CSdata.maturities(2:end)/4,CSdata.CSBetta_CI95Boot(1,2:end),'--k')
    plot(CSdata.maturities(2:end)/4,CSdata.CSBetta_CI95Boot(2,2:end),'--k')
end
plot(CSdata.maturities(2:end)/4,CSdata.CSbetta(2,2:end),'-k')
plot(CSmodel.maturities(2:end)/4,CSmodel.CSbetta(2,2:end),'-ok','MarkerSize',10)
plot(CSdata.maturities(2:end)/4,CSdata.CSbetta(2,2:end)*0+1,':k')

set(gca,'FontSize',FontSizeValue)
%ylabel('$\beta_k $','Interpreter','Latex','FontSize',FontSizeValue);
xlabel('Maturity in years','FontSize',FontSizeValue)
legend({'CI 95 pct','Data','Model'},...
    'Interpreter','Latex','Orientation','horizontal','FontSize',FontSizeValue+2,'EdgeColor',[0.15 0.15 0.15],...
    'Position',[0.384822896027229 0.939478465696058 0.243629479375424 0.0675996218505801]);
legend boxoff  
axis([min(CSdata.maturities(2:end)/4) max(CSdata.maturities(2:end)/4) min(CSdata.CSBetta_CI95Boot(:))*1.1 yMax])


%% Risk-adjusted CS loadings
%Figure 4
figure('Name','Risk-adjusted CS loadings and the Model','NumberTitle','off','Position',figureSize)

hold on
if version == 1
    xaxis       = CSdata.maturities(2:end)/4; 
    reverseaxis = CSdata.maturities(length(CSdata.maturities):-1:2)/4; 
    index       = 2:length(CSdata.CSbetta(2,:));
    reversIndex = length(CSdata.CSbetta(2,:)):-1:2;
    %grpyat = [xaxis'       outEstim.CS_riskAdj.CSBetta_CI95Boot(1,index)';...
    %      reverseaxis' outEstim.CS_riskAdj.CSBetta_CI95Boot(2,reversIndex)'];
    grpyat = [xaxis'       outEstim.CS_riskAdj.CSBetta_prcBootCI95(1,index)';...
          reverseaxis' outEstim.CS_riskAdj.CSBetta_prcBootCI95(2,reversIndex)'];
    patch(grpyat(:,1),grpyat(:,2),[0.8 0.8 0.8],'edgecolor',[0.6 0.6 0.6]);
else
    plot(CSdata.maturities(2:end)/4,outEstim.CS_riskAdj.CSBetta_CI95Boot(1,2:end),'--k')
    plot(CSdata.maturities(2:end)/4,outEstim.CS_riskAdj.CSBetta_CI95Boot(2,2:end),'--k')
end
plot(CSdata.maturities(2:end)/4,outEstim.CS_riskAdj.CSbetta(2,2:end),'-ok','MarkerSize',10)
%plot(CSdata.maturities(2:end)/4,outEstim0.CS_riskAdj.CSbetta(2,2:end),'--k')
plot(CSdata.maturities(2:end)/4,CSdata.CSbetta(2,2:end)*0+1,':k')
%plot(CSdata.maturities(2:end)/4,outEstim0.CS_riskAdj.CSBetta_CI95Boot(1,2:end),'--k')
%plot(CSdata.maturities(2:end)/4,outEstim0.CS_riskAdj.CSBetta_CI95Boot(2,2:end),'--k')

set(gca,'FontSize',FontSizeValue)
%ylabel('$\beta_k^{Adj} $','Interpreter','Latex','FontSize',FontSizeValue);
xlabel('Maturity in years','FontSize',FontSizeValue)
legend({'CI 95 pct','$M^{M,CS}$'},...
    'Interpreter','Latex','Orientation','horizontal','FontSize',FontSizeValue,'EdgeColor',[0.15 0.15 0.15],...
    'Position',[0.384822896027229 0.939478465696058 0.243629479375424 0.0675996218505801]);
legend boxoff  
tmp = [outEstim.CS_riskAdj.CSbetta(2,2:end),outEstim.CS_riskAdj.CSbetta(2,2:end),...
    outEstim.CS_riskAdj.CSBetta_CI95Boot(:)'];
yMinNew = min(tmp);
yMaxNew = max([tmp,4]);
axis([min(CSdata.maturities(2:end)/4) max(CSdata.maturities(2:end)/4) min(yMin,yMinNew) max(yMax,yMaxNew)])

%% Joint plot
figureSize      = [0 0 900 600+300]; % (0,0) size in x size in y
figure('Name','Joint Plot - CS loadings and the Model','NumberTitle','off','Position',figureSize)

yMax        = 3;
yMin        = -4;
subplot(2,1,1)
hold on
if version == 1
    xaxis       = CSdata.maturities(2:end)/4; 
    reverseaxis = CSdata.maturities(length(CSdata.maturities):-1:2)/4; 
    index       = 2:length(CSdata.CSbetta(2,:));
    reversIndex = length(CSdata.CSbetta(2,:)):-1:2;
    %grpyat = [xaxis'       CSdata.CSBetta_CI95Boot(1,index)';...
    %      reverseaxis' CSdata.CSBetta_CI95Boot(2,reversIndex)'];
    grpyat = [xaxis'       CSdata.CSBetta_prcBootCI95(1,index)';...
          reverseaxis' CSdata.CSBetta_prcBootCI95(2,reversIndex)'];
    patch(grpyat(:,1),grpyat(:,2),[0.8 0.8 0.8],'edgecolor',[0.6 0.6 0.6]);
else
    plot(CSdata.maturities(2:end)/4,CSdata.CSBetta_CI95Boot(1,2:end),'--k')
    plot(CSdata.maturities(2:end)/4,CSdata.CSBetta_CI95Boot(2,2:end),'--k')
end
plot(CSdata.maturities(2:end)/4,CSdata.CSbetta(2,2:end),'-k')
plot(CSmodel.maturities(2:end)/4,CSmodel.CSbetta(2,2:end),'-ok','MarkerSize',10)
plot(CSdata.maturities(2:end)/4,CSdata.CSbetta(2,2:end)*0+1,':k')

set(gca,'FontSize',FontSizeValue)
title('Ordinary Campbell-Shiller Loadings: $\beta_k $','Interpreter','Latex','FontSize',FontSizeValue-2);
xlabel('Maturity in years','FontSize',FontSizeValue)
legend({'CI 95 pct','Data','Model'},...
    'Interpreter','Latex','Orientation','horizontal','FontSize',FontSizeValue,'EdgeColor',[0.15 0.15 0.15],...
    'Position',[0.384822896027229 0.939478465696058 0.243629479375424 0.0675996218505801]);
legend boxoff  
axis([min(CSdata.maturities(2:end)/4) max(CSdata.maturities(2:end)/4) min(CSdata.CSBetta_CI95Boot(:))*1.1 yMax])


% Risk-adjusted CS loadings
subplot(2,1,2)
hold on
if version == 1
    xaxis       = CSdata.maturities(2:end)/4; 
    reverseaxis = CSdata.maturities(length(CSdata.maturities):-1:2)/4; 
    index       = 2:length(CSdata.CSbetta(2,:));
    reversIndex = length(CSdata.CSbetta(2,:)):-1:2;
    %grpyat = [xaxis'       outEstim.CS_riskAdj.CSBetta_CI95Boot(1,index)';...
    %      reverseaxis' outEstim.CS_riskAdj.CSBetta_CI95Boot(2,reversIndex)'];
    grpyat = [xaxis'       outEstim.CS_riskAdj.CSBetta_prcBootCI95(1,index)';...
          reverseaxis' outEstim.CS_riskAdj.CSBetta_prcBootCI95(2,reversIndex)'];
    patch(grpyat(:,1),grpyat(:,2),[0.8 0.8 0.8],'edgecolor',[0.6 0.6 0.6]);
else
    plot(CSdata.maturities(2:end)/4,outEstim.CS_riskAdj.CSBetta_CI95Boot(1,2:end),'--k')
    plot(CSdata.maturities(2:end)/4,outEstim.CS_riskAdj.CSBetta_CI95Boot(2,2:end),'--k')
end
plot(CSdata.maturities(2:end)/4,outEstim.CS_riskAdj.CSbetta(2,2:end),'-ok','MarkerSize',10)
plot(CSdata.maturities(2:end)/4,CSdata.CSbetta(2,2:end)*0+1,':k')


set(gca,'FontSize',FontSizeValue)
title('Risk-Adjusted Campbell-Shiller Loadings: $\beta_k^{Adj} $','Interpreter','Latex','FontSize',FontSizeValue-2);
xlabel('Maturity in years','FontSize',FontSizeValue)
tmp = [outEstim.CS_riskAdj.CSbetta(2,2:end),outEstim.CS_riskAdj.CSbetta(2,2:end),...
    outEstim.CS_riskAdj.CSBetta_CI95Boot(:)'];
yMinNew = min(tmp);
yMaxNew = max([tmp,4]);
axis([min(CSdata.maturities(2:end)/4) max(CSdata.maturities(2:end)/4) min(yMin,yMinNew) max(yMax,yMaxNew)])


 
end
